package cn.well.cloud.common;

import com.alibaba.fastjson.JSONObject;

/**
 * 保存API请求头部信息至本次请求线程，请求线程内共享该信息。
 * 
 * Created by wison on 2019年8月15日.
 *
 */
public class HttpHeader {
    public static final String TOKEN = "token";
    public static final String IP = "ip";
    public static String USERID = "userId";
    public static String REQUEST_BODY = "requestBody";

    /**
     * 请求线程内共享对象
     */
    public static ThreadLocal<HttpHeader> local = new ThreadLocal<HttpHeader>();


    private String token;
    private String ip;
    private Long userId;
    private JSONObject requestBody; //用户在某房间中的身份
    
    public static void set(HttpHeader header) {
        local.set(header);
    }

    
    public static HttpHeader get() {
        return local.get();
    }

    public String getToken() {
        return token;
    }

    public void setToken(String token) {
        this.token = token;
    }

    public String getIp() {
        return ip;
    }

    public void setIp(String ip) {
        this.ip = ip;
    }
    
    

    public Long getUserId() {
        return userId;
    }


    public void setUserId(Long userId) {
        this.userId = userId;
    }
    
    

    public JSONObject getRequestBody() {
        return requestBody;
    }


    public void setRequestBody(JSONObject requestBody) {
        this.requestBody = requestBody;
    }


    @Override
    public String toString() {
        String EQ = "=";
        String SEM = ";";
        StringBuilder sb = new StringBuilder();
        sb.append(USERID).append(EQ).append(userId).append(SEM);
        sb.append(IP).append(EQ).append(ip).append(SEM);
        return sb.toString();
    }

}
